import networkx as nx
from timer import Timerx
from itertools import izip

def read_graph(file_path, delimiter=' '):
    G = nx.Graph()
    
    with open(file_path) as edges_file:
        for line in edges_file:
            source, target = line.rstrip().split(delimiter)
            G.add_edge(source, target)
    
    return G

def build_U(nodes_list):
    """
    Returns a list U which is the universal edges set that contains 
    every possible edge that can be in the graph. 
    The size of this set N*(N-1)/2 where N is the number of nodes/vertices.
    """
    U = list()
 
    for i, node1 in enumerate(nodes_list):
        for node2 in nodes_list[i+1:]:
            edge = (node1,node2)
            U.append(edge)
                
    return U

def build_Y(G, U):
    """
    Builds the Y ground-truth list that contains a label
    for each edge in the universal to indicate if the edge
    really exists in the graph or not.
    
    Parameters:
    G: the Networkx graph.
    U: the universal edges set that contains every possible edge in the graph.
    """
    
    Y = list()
    
    for edge in U:
        node1 = edge[0]
        node2 = edge[1]
        if G.has_edge(node1,node2):
            Y.append(1)
        else:
            Y.append(0)
            
    return Y





















